//
//  WJPLCell.m
//  WJBSApp
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 王景伟. All rights reserved.
//

#import "WJPLCell.h"

@interface WJPLCell ()

@property (nonatomic,strong) WJBaseImageView *sexImageView;

@property (nonatomic,strong) WJBaseLable *nameLable;

@property (nonatomic,strong) WJBaseLable *nrLable;


@end

@implementation WJPLCell

-(void)dealloc
{
    [_model release];
    [_nrLable release];
    [_sexImageView release];
    [_nameLable release];
    Block_release(self.followIDBlock);
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createView];
        
    }
    return self;
}

- (void)createView
{
    
    self.sexImageView = [[WJBaseImageView alloc]init];
    [self.contentView addSubview:self.sexImageView];
    self.sexImageView.backgroundColor = BSClearColor;
    [_sexImageView release];

    
    self.nameLable = [[WJBaseLable alloc]init];
    [self.contentView addSubview:self.nameLable];
    self.nameLable.font = [UIFont systemFontOfSize:13];
    self.nameLable.textColor = BSGrayColor;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    self.nameLable.userInteractionEnabled = YES;
    [self.nameLable addGestureRecognizer:tap];                
    [tap release];
    [_nameLable release];
    
    
    
    self.nrLable = [[WJBaseLable alloc]init];
    [self.contentView addSubview:self.nrLable];
    self.nrLable.font = [UIFont systemFontOfSize:15];
    self.nrLable.numberOfLines = 0;
    [_nrLable release];
    
    
}





- (void)setModel:(WJPLmodel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    if ([model.userModel.sex isEqualToString:@"m"]) {
        self.sexImageView.image = [UIImage imageNamed:@"Profile_manIcon"];
    }else{
        self.sexImageView.image = [UIImage imageNamed:@"Profile_womanIcon"];
    }
    
    self.nameLable.text = model.userModel.username;
    
    self.nrLable.text = model.content;
    
    
}



-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.sexImageView.frame = CGRectMake(10, 10, 20, 20);
    self.nameLable.frame = CGRectMake(35, 10, WIDTH - 35, (HEIGHT/9 - 20)/2);
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:16]};
    CGRect rect = [self.nrLable.text boundingRectWithSize:CGSizeMake( WIDTH - 20, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];

    self.nrLable.frame = CGRectMake(10, (HEIGHT/9 - 20)/2 + 10, WIDTH - 20, rect.size.height);
    
}

-(void)tapAction:(UITapGestureRecognizer *)tap{
    
    NSLog(@"点击了人头像");
    if (self.followIDBlock) {
        
        self.followIDBlock(self.model.userModel.id,self.model.userModel.username);
        
    }
    
}





@end
